Processing math: 100%

Sphere intersection

We wish to find out when a ray hits a sphere. Our spheres will be defined by the implicit equation of a sphere (pc)(pc)r2=0

where p) is the a possible position on the sphere, c) is the center of the sphere, and r is the radius.

Given the parametric equation of a ray r=e+td  we can solve for the intersection by setting the equations equal to one another. Put the ray equation in place of the p in the sphere equation results in:

(e+tdc)(e+tdc)r2=0;

This expands to:

(dd)t2+2d(ec)t+(ec)(ec)r2=0

This result is solvable using the quadratic formula: x=b±b24ac2a

where

a=dd)

b=2d(ec)

c=(ec)(ec)r2=0

We can then solve for t: t=d(ec)±(d(ec))2(dd)((ec)(ec)r2)(dd)